package com.javabi.boardgame.game.monopoly.money;

import java.util.EnumMap;
import java.util.Map;

public class Money {

	private final Map<Denomination, Amount> amountMap = new EnumMap<Denomination, Amount>(Denomination.class);

	public Money() {
		for (Denomination denomination : Denomination.values()) {
			amountMap.put(denomination, new Amount(denomination, 0));
		}
	}

	public Amount getAmount(Denomination denomination) {
		if (denomination == null) {
			throw new NullPointerException("denomination");
		}
		return new Amount(amountMap.get(denomination));
	}

	public void remove(Amount amount) {
		if (amount == null) {
			throw new NullPointerException("amount");
		}

		// Remove
		Amount current = amountMap.get(amount.getDenomination());
		current.remove(amount.get());
	}

	public void add(Amount amount) {
		if (amount == null) {
			throw new NullPointerException("amount");
		}

		// Add
		Amount current = amountMap.get(amount.getDenomination());
		current.add(amount.get());
	}

	public int getCost() {
		int cost = 0;
		for (Amount amount : amountMap.values()) {
			cost += amount.getCost();
		}
		return cost;
	}

}
